package sysman.action;

import java.util.List;
import java.util.HashMap;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springside.core.web.StrutsEntityAction;
import org.apache.struts.validator.LazyValidatorForm;

import sysman.dao.OrderDealDao;
import sysman.model.OrderDealHistory;

import common.Globals;
import common.PageInfo;

/**
 * 
 * <actionTitle>
 * 
 * @<author>
 * @<since>
 * @<version>
 *
 */
public class OrderDealAction extends StrutsEntityAction<OrderDealHistory, OrderDealDao> {
	
	private OrderDealDao orderDealDao;

	public OrderDealDao getOrderDealDao() {
		return orderDealDao;
	}

	public void setOrderDealDao(OrderDealDao orderDealDao) {
		this.orderDealDao = orderDealDao;
	}

	/**
	 *列表
	 */
	@Override
	public ActionForward list(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		LazyValidatorForm lvForm = (LazyValidatorForm)form;
		PageInfo pageInfo = new PageInfo(request);
		HashMap<String, String> hm = new HashMap<String, String>();
		//TODO 组装查询条件
		
		String id = (String)lvForm.get("s_id");
		hm.put("id" ,id);
		String taskId = (String)lvForm.get("taskId");
		hm.put("taskId" ,taskId);
		String result = (String)lvForm.get("s_result");
		hm.put("result" ,result);
		String reason = (String)lvForm.get("s_reason");
		hm.put("reason" ,reason);
		String creator = (String)lvForm.get("s_creator");
		hm.put("creator" ,creator);
		String createTime = (String)lvForm.get("s_createTime");
		hm.put("createTime" ,createTime);

				
		try {
			List<OrderDealHistory> poList =this.getOrderDealDao().getRecords(taskId,pageInfo);
			request.setAttribute("list", poList);
			request.setAttribute("taskId", taskId);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		return mapping.findForward(Globals.FORWARD_LIST);
	}
	
	/**
	 * 删除
	 */
	@Override
	public ActionForward delete(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {
		super.delete(mapping, form, request, response);
		
		return this.list(mapping, form, request, response);
	}

	/**
	 * 保存
	 */
	@Override
	public ActionForward save(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response) {		
		super.save(mapping, form, request, response);
		
		return this.list(mapping, form, request, response);
	}
	
	/**
	 * 该方法被delete方法调用
	 */
	@Override
	protected void doDeleteEntity(ActionForm form, HttpServletRequest request) {
		String ids = request.getParameter("ids");
		try {
			if (ids != null && !"".equals(ids.trim())) {
				getEntityManager().deleteByIds(ids);
				// TODO 修改操作事件，参考logWrite方法要求
				//logsManager.logWrite(request, "", "操作日志", 0);
			}
		} catch (Exception e) {
			// TODO 修改操作事件，参考logWrite方法要求
			//logsManager.logWrite(request, "", "操作日志", 0);
		}
	}
}


